/*
 *  Resource.h
 *  SypXIPhone
 *
 *  Created by Luv Khemani on 5/14/10.
 *  Copyright 2010 Luv Khemani. All rights reserved.
 *
 */

#pragma once
#ifndef SYPX_RESOURCE
#define SYPX_RESOURCE

#include "Types.h"

namespace SypX
{
	///A Resource is any object which is used/referenced multiple times. Therefore Resources are reference counted.
	///In future, a Resource may self deallocate once it's reference count reaches 0 or be cleared by a cleanup command.
	class SYPXAPI Resource
	{
	public:
		///Default resource constructor
		Resource();
		///Adds a reference count to this resource. Should only be called when using the resource.
		virtual void addRef();
		///Removes a reference count to this resource. Should only be called when no longer using the Resource
		///and a prior call to addRef() was used.
		virtual void removeRef();
		///Sets the Filename for this Resource. Fileloaders should take into account existing loaded resources
		///before attempting to load files.(Requires a Resource Registry TODO)
		void setFileName(const String& file);
		///Returns the filename of this Resource(if any)
		const String& getFileName();
		///Returns the number of references using this Resource
		UInt getNumRef();
		///Returns a unique ID, used for giving unique names to non-disk based Resources
		UInt getUniqueID();
	protected:
		///Resource deconstructor(Protected to prevent client from manually deleting it)
		virtual ~Resource();
		///ResourceManager is in charge of clearing all unused Resources
		friend class ResourceManager;
	private:
		UInt count;
		String filename;
		static UInt uniqueID;
	};

}

#endif
